1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| type covStruct struct { projectId int projectName string projectCreator string coverage string }
func drawTable(covs []covStruct) ([]byte, error) { slices.SortFunc(covs, func(a, b covStruct) int { return strings.Compare(a.projectCreator+a.projectName, b.projectCreator+b.projectName) }) header := []string{"项目 ID", "项目名称", "创建人", "测试覆盖率"} data := lo.Map(covs, func(item covStruct, index int) []string { var conv string if item.coverage != "" { conv = item.coverage + "%" } else { conv = "无" } return []string{strconv.Itoa(item.projectId), item.projectName, item.projectCreator, conv} }) spans := []int{1, 4, 2, 2}
fontBs, _ := os.ReadFile("Noto Sans Mono CJKsc-VF.ttf") _ = charts.InstallFont("noto", fontBs) font, _ := charts.GetFont("noto") charts.SetDefaultFont(font) p, err := charts.TableOptionRender(charts.TableChartOption{ Header: header, Data: data, Spans: spans, Width: 1300, }) if err != nil { return nil, err } return p.Bytes() }
|